﻿namespace dPet.Application.Bootstrapper
{
	using AutoMapper;
	using dPet.Application.DataObjects;
	using dPet.Domain.Models;
	using Hangerd.Bootstrapper;
	using Microsoft.Practices.Unity;

	public class InitServiceTask : InitServiceBootstrapperTask
	{
		public InitServiceTask(IUnityContainer container) : base(container) { }

		public override int Order { get { return 998; } }

		public override void Execute()
		{
			this.ConfigureAutoMapper();
		}

		private void ConfigureAutoMapper()
		{
			Mapper.CreateMap<Hospital, HospitalDto>();
			Mapper.CreateMap<Staff, StaffDto>();
			Mapper.CreateMap<StaffRole, StaffRoleDto>()
				.ForMember(srDto => srDto.Privileges, mceSr =>
					mceSr.ResolveUsing(sr => { return (PrivilegesDto)sr.Privileges; })
				);
			Mapper.CreateMap<ProductCategory, ProductCategoryDto>();
			Mapper.CreateMap<ProductSubCategory, ProductSubCategoryDto>();
			Mapper.CreateMap<Product, ProductDto>();
			Mapper.CreateMap<ProductInventory, ProductInventoryDto>();
			Mapper.CreateMap<InventoryBatch, InventoryBatchDto>();
			Mapper.CreateMap<InventoryBatchDetail, InventoryBatchDetailDto>();
			Mapper.CreateMap<SaleOrder, SaleOrderDto>()
				.ForMember(soDto => soDto.MembershipLevel, mceSo =>
					mceSo.ResolveUsing(so => { return (MembershipLevelDto)so.MembershipLevel; })
				)
				.ForMember(soDto => soDto.PaymentMethod, mceSo =>
					mceSo.ResolveUsing(so => { return (PaymentMethodDto)so.PaymentMethod; })
				)
				.ForMember(soDto => soDto.Status, mceSo =>
					mceSo.ResolveUsing(so => { return (OrderStatusDto)so.Status; })
				);
			Mapper.CreateMap<SaleOrderLine, SaleOrderLineDto>();
			Mapper.CreateMap<BillTemplate, BillTemplateDto>();
			Mapper.CreateMap<InventoryLORecord, InventoryLORecordDto>()
				.ForMember(ilorDto => ilorDto.LOType, mceIlor =>
					mceIlor.ResolveUsing(ilor => { return (InventoryLOTypeDto)ilor.LOType; })
				);
			Mapper.CreateMap<InventoryAlarmItem, InventoryAlarmItemDto>()
				.ForMember(iaiDto => iaiDto.AlarmType, mceIai =>
					mceIai.ResolveUsing(iai => { return (InventoryAlarmTypeDto)iai.AlarmType; })
				);
			Mapper.CreateMap<ServiceCategory, ServiceCategoryDto>();
			Mapper.CreateMap<ServiceItem, ServiceItemDto>();
			Mapper.CreateMap<ServiceItemSKU, ServiceItemSKUDto>();
			Mapper.CreateMap<ServiceSKUProperty, ServiceSKUPropertyDto>();
			Mapper.CreateMap<ServiceSKUPropertyValue, ServiceSKUPropertyValueDto>();
			Mapper.CreateMap<ServiceOrder, ServiceOrderDto>()
				.ForMember(soDto => soDto.MembershipLevel, mceSo =>
					mceSo.ResolveUsing(so => { return (MembershipLevelDto)so.MembershipLevel; })
				)
				.ForMember(soDto => soDto.PaymentMethod, mceSo =>
					mceSo.ResolveUsing(so => { return (PaymentMethodDto)so.PaymentMethod; })
				)
				.ForMember(soDto => soDto.Status, mceSo =>
					mceSo.ResolveUsing(so => { return (OrderStatusDto)so.Status; })
				);
			Mapper.CreateMap<ServiceOrderLine, ServiceOrderLineDto>();
		}
	}
}
